package com.dys.designpattern.singleton.applicationscenarios;

/**
 * @author 田建松
 * @version V1.0.0
 * @description 2.双重检查
 * @date 2024/5/10
 * @since 1.0
 */
public class SerialGenerator_DCL {

    private long code;

    private static volatile SerialGenerator_DCL instance;

    private SerialGenerator_DCL(){}

    public synchronized long next(){
        return ++code;
    }

    public static SerialGenerator_DCL getInstance() {
        if (instance==null) {
            synchronized (SerialGenerator_DCL.class) {
                if (instance == null) {
                    instance = new SerialGenerator_DCL();
                }
            }

        }
        return instance;
    }
}
